package com.manger.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zbf.entity.ResponseResult;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.*;

/**
 * 作者: LCG
 * 日期: 2019/8/14 18:32
 * 描述:
 */
@RestController
public class UserController {


    @RequestMapping("test")
    public ResponseResult test(HttpServletResponse response){
        ResponseResult responseResult = ResponseResult.getResponseResult();
        responseResult.setResult("123456");
        return responseResult;
    }


    public static void main(String[] args) {

        try {
            getJsonObjFromResource();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    }


    public static JSONObject getJsonObjFromResource() throws FileNotFoundException, UnsupportedEncodingException {
        JSONObject json = null;

        FileInputStream file = null;
        BufferedReader reader = null;
        InputStreamReader inputFileReader = null;

        String fileName = "C:\\Users\\lenovo\\Desktop\\json\\respose.json";
        String content = "";
        String tempString = null;

        try {
            file = new FileInputStream(fileName);
            inputFileReader = new InputStreamReader(file, "utf-8");
            reader = new BufferedReader(inputFileReader);
            // 一次读入一行，直到读入null为文件结束
            while ((tempString = reader.readLine()) != null) {
                content += tempString;
            }

           json=JSON.parseObject(content);
            json.get("ruleAnomalyDetectRusults");
            //json = JSONObject.fromObject(content);
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e1) {
                }
            }
        }

        return json;
    }

}
